import { getSongSheetSongList } from '@/api/recommend'
import { getSongUrl } from '@/api/common'
import { processSongUrl, processSongPic } from '@/utils'
import { getSingerSongs, getSongDetail } from '@/api/singer'
export default function useDetailCom(
  request: typeof getSongSheetSongList | typeof getSingerSongs,
  getSongPic = false,
  requestParam: {
    more: boolean
    limit: number
    offset: number
  }
) {
  const route = useRoute()
  const songList = ref<ISongItem[]>([])
  const loading = ref<boolean>(false)
  onMounted(async () => {
    const id = Number(route.params.id)
    loading.value = true
    const { songs, more } = await request(id, requestParam.offset, requestParam.limit)
    requestParam.more = more
    const ids = songs.map(({ id }) => id)
    const { data: urls } = await getSongUrl(ids)
    // 根据歌曲id获取到对应的url播放地址
    processSongUrl(songs, urls)
    if (getSongPic) {
      const { songs: data } = await getSongDetail(ids)
      processSongPic(songs, data)
    }
    loading.value = false
    songList.value = songs
  })

  return {
    songList,
    loading
  }
}
